package GUILayer;

import b4.advancedgui.menu.AccordionItem;
import b4.advancedgui.menu.AccordionLeafItem;
import b4.advancedgui.menu.AccordionMenu;
import b4.advancedgui.menu.AccordionRootItem;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import java.awt.BorderLayout;
import javax.swing.BoxLayout;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Box;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.JList;
import javax.swing.AbstractListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.LayoutStyle.ComponentPlacement;

import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Rectangle;
import java.awt.ScrollPane;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Component;
import CtrLayer.*;
import javax.swing.ListSelectionModel;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import java.beans.VetoableChangeListener;
import java.beans.PropertyChangeEvent;


public final class NewJFrame extends javax.swing.JFrame {

	private AccordionMenu menu1;
	private JournalCtr journalCtr;
	private SchemeCtr schemeCtr;
	private JTextField textField_20;
	private JTextField textField_21;
	private JTextField textField_23;
	private JTextField textField_24;
	private JTextField textField_25;
	private JTextField textField_26;
	private SessionCtr sessionCtr;
	private JPanel panel_31;
	private ArrayList<String> documentation;
	private JComboBox moduleBox;
	private JComboBox themeBox;

	public NewJFrame() {
		setResizable(false);
		/**
		 * Changes Look & Feel to Nimbus. And sets icon for JFrame.
		 */
		journalCtr = new JournalCtr();
		sessionCtr = new SessionCtr();
		schemeCtr = new SchemeCtr();
		try {
			UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
			setIconImage(Toolkit
					.getDefaultToolkit()
					.getImage(
							this.getClass()
									.getResource(
											"b4/advancedgui/menu/resources/green_arrow_right.png")));
		} catch (Exception ex) {
			Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null,
					ex);

		}
		initComponents();

		setExtendedState(Frame.MAXIMIZED_BOTH);

		// menu 1. Creates a standard menu, gray background, Center Alignment of
		// Roots and Leafs, small monospaced font.
		System.out.println(getMenuDescriptor());
		System.out.println(getSampleMenuDescriptor());
		menu1 = new AccordionMenu(getMenuDescriptor());

		// createSampleMenuStructure(menu1);
		menu1.setBackground(new Color(204, 204, 204));
		menu1.setMenuHorizontalAlignment(AccordionItem.CENTER);
		menu1.setLeafHorizontalAlignment(AccordionItem.CENTER);
		menu1.setFont(new Font("monospaced", Font.PLAIN, 13));
		setMouseAdapter(menu1);
		cont1.add(menu1);

		JPanel panel_8 = new JPanel();
		panel_8.setBackground(new Color(153, 153, 153));
		panel_8.setLayout(new BoxLayout((Container) null, BoxLayout.LINE_AXIS));
		getContentPane().setLayout(new BorderLayout(0, 0));

		JPanel panel_10 = new JPanel();
		jTabbedPane1.addTab("Create Journal", null, panel_10, null);
		panel_10.setLayout(new BoxLayout(panel_10, BoxLayout.Y_AXIS));

		JPanel panel_24 = new JPanel();
		panel_24.setBorder(new TitledBorder(null, "General Information",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_10.add(panel_24);
		panel_24.setLayout(new BoxLayout(panel_24, BoxLayout.Y_AXIS));

		JPanel panel_25 = new JPanel();
		panel_24.add(panel_25);

		JLabel lblNewLabel_12 = new JLabel("  Module");
		panel_25.add(lblNewLabel_12);

		moduleBox = new JComboBox();

		moduleBox.setModel(new DefaultComboBoxModel(new String[] { "Module 1",
				"Module 2", "Module 3", "Module 4", "Module 5", "Module 6",
				"Module 7", "Module 8", "Module 9", "Module 10", "Module 11",
				"Module 12" }));
		panel_25.add(moduleBox);
		moduleBox.setSelectedIndex(0);

		JLabel lblNewLabel_13 = new JLabel("              Theme");
		panel_25.add(lblNewLabel_13);

		themeBox = new JComboBox();
		themeBox.setEditable(true);
		themeBox.setModel(new DefaultComboBoxModel(new String[] { "" }));
		panel_25.add(themeBox);

		JPanel panel_26 = new JPanel();
		FlowLayout flowLayout_2 = (FlowLayout) panel_26.getLayout();
		flowLayout_2.setHgap(10);
		panel_24.add(panel_26);

		final JLabel lblHospitalizationDate = new JLabel("Hosp. date");
		panel_26.add(lblHospitalizationDate);

		JButton btnCalendar = new JButton("Calendar");
		btnCalendar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				new SessionCalendar(lblHospitalizationDate);
			}
		});
		panel_26.add(btnCalendar);

		JLabel lblNewLabel_14 = new JLabel("  Name");
		panel_26.add(lblNewLabel_14);

		textField_20 = new JTextField();
		panel_26.add(textField_20);
		textField_20.setColumns(10);

		JPanel panel_27 = new JPanel();
		FlowLayout flowLayout_1 = (FlowLayout) panel_27.getLayout();
		panel_24.add(panel_27);

		JLabel lblRelatives = new JLabel("       Relatives");
		panel_27.add(lblRelatives);

		textField_23 = new JTextField();
		textField_23.setColumns(10);
		panel_27.add(textField_23);

		JLabel lblNewLabel_15 = new JLabel("            Age");
		panel_27.add(lblNewLabel_15);

		textField_21 = new JTextField();
		panel_27.add(textField_21);
		textField_21.setColumns(10);

		JPanel panel_28 = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel_28.getLayout();
		flowLayout.setHgap(7);
		panel_24.add(panel_28);

		JLabel lblContactCauses = new JLabel("    Contact causes ");
		panel_28.add(lblContactCauses);

		textField_24 = new JTextField();
		textField_24.setColumns(12);
		panel_28.add(textField_24);

		JLabel lblHypersensitivity = new JLabel("Hypersensitivity");
		panel_28.add(lblHypersensitivity);

		textField_25 = new JTextField();
		textField_25.setColumns(10);
		panel_28.add(textField_25);

		JPanel panel_29 = new JPanel();
		panel_24.add(panel_29);

		JLabel lblNewLabel_16 = new JLabel("Medical Diagnosis");
		panel_29.add(lblNewLabel_16);

		textField_26 = new JTextField();
		panel_29.add(textField_26);
		textField_26.setColumns(20);

		JLabel lblSex = new JLabel("           Sex");
		panel_29.add(lblSex);

		textField_27 = new JTextField();
		panel_29.add(textField_27);
		textField_27.setColumns(10);

		JPanel panel_30 = new JPanel();
		panel_30.setBorder(new TitledBorder(null, "Nursing Documentation",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_24.add(panel_30);

		JButton btnNewButton_5 = new JButton("Create Nursing Documentation");
		btnNewButton_5.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {

				new NursingDocumentation(textField_20.getText());

			}
		});
		panel_30.add(btnNewButton_5);

		JPanel panel_18 = new JPanel();
		panel_18.setBorder(new TitledBorder(null, "Medical Record",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_10.add(panel_18);
		panel_18.setLayout(new BoxLayout(panel_18, BoxLayout.Y_AXIS));

		JPanel panel_19 = new JPanel();
		panel_18.add(panel_19);
		panel_19.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		final JComboBox comboBoxsSchemes = new JComboBox();

		comboBoxsSchemes.setModel(new DefaultComboBoxModel(new String[] {
				"LabSchema", "Nutrition risk screening", "Barden Scale",
				"Temperature Scheme" }));
		panel_19.add(comboBoxsSchemes);

		JPanel panel_34 = new JPanel();
		panel_34.setBorder(new TitledBorder(null, "Schemes",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_18.add(panel_34);
		panel_34.setLayout(new BorderLayout(0, 0));

		tableSchemes = new JTable();
		tableSchemes.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		JScrollPane scrollPane = new JScrollPane(tableSchemes);

		panel_34.add(scrollPane);

		JPanel panel_21 = new JPanel();
		panel_18.add(panel_21);
		panel_21.setLayout(new BoxLayout(panel_21, BoxLayout.X_AXIS));

		JButton attachButton = new JButton("Attach Scheme");
		panel_21.add(attachButton);

		JPanel panel_22 = new JPanel();
		panel_18.add(panel_22);
		panel_22.setLayout(new BorderLayout(0, 0));
		
		
		selectedSchemes = new JTable();
		JScrollPane scrollPaneSelected = new JScrollPane(selectedSchemes);
		panel_22.add(scrollPaneSelected);
		selectedSchemes.setModel(new DefaultTableModel(new Object[][] {}, new String[] {"Name","Type"}));
	
	
		
		
		

		JPanel panel_23 = new JPanel();
		panel_18.add(panel_23);


		JButton finalizeButton = new JButton("Finalize");
		panel_23.add(finalizeButton);

		JButton btnNewButton_4 = new JButton("Remove Scheme");
		panel_23.add(btnNewButton_4);
		
		moduleBox.setSelectedIndex(0);



		comboBoxsSchemes.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				if (comboBoxsSchemes.getSelectedIndex() == 0) {

					final String[][] schemasName = schemeCtr
							.getAllLabSchemeMeasurementsNames();
					String[] columnNames = { " Name" };
					DefaultTableModel model = new DefaultTableModel(
							schemasName, columnNames);

					tableSchemes.setModel(model);
				}
				
				
				if (comboBoxsSchemes.getSelectedIndex() == 1) {

					String[][] schemesInfo = schemeCtr
							.getAllNutritionRiskSchemesInformation();
					String[] columnNames = { "Name",
							"Impaired Nutritional Rusk", "Severity of Disease" };

					final String[][] schemeInfoDetailed = new String[schemesInfo.length][3];

					for (int i = 0; i < schemesInfo.length; i++) {

						schemeInfoDetailed[i][0] = schemesInfo[i][0];

						switch (Integer.parseInt(schemesInfo[i][1])) {
						case 0:
							schemeInfoDetailed[i][1] = "Normal Score - 0";
							break;
						case 1:
							schemeInfoDetailed[i][1] = "Easy Score - 1";
							break;
						case 2:
							schemeInfoDetailed[i][1] = "Moderate Score - 2";
							break;
						case 3:
							schemeInfoDetailed[i][1] = "Difficult Score - 3";
							break;
						default:
							schemeInfoDetailed[i][1] = "Invalid Score";
							break;
						}

						switch (Integer.parseInt(schemesInfo[i][2])) {
						case 0:
							schemeInfoDetailed[i][2] = "Normal Score - 0";
							break;
						case 1:
							schemeInfoDetailed[i][2] = "Easy Score - 1";
							break;
						case 2:
							schemeInfoDetailed[i][2] = "Moderate Score - 2";
							break;
						case 3:
							schemeInfoDetailed[i][2] = "Difficult Score - 3";
							break;
						default:
							schemeInfoDetailed[i][2] = "Invalid Score";
							break;
						}

					}

					DefaultTableModel model = new DefaultTableModel(
							schemeInfoDetailed, columnNames);
					tableSchemes.setModel(model);
				}
				
				
				if (comboBoxsSchemes.getSelectedIndex() == 2) {

					final String[][] scalesInfo = schemeCtr
							.getAllBradenScalesInformation();

					String[] columnNames = { " Name" };
					DefaultTableModel model = new DefaultTableModel(scalesInfo,
							columnNames);
					tableSchemes.setModel(model);
				}
				
				
				if (comboBoxsSchemes.getSelectedIndex() == 3) {

					final String[][] schemasName = schemeCtr
							.getAllTemperatureMeasurementsNames();
					String[] columnNames = { " Name" };
					DefaultTableModel model = new DefaultTableModel(
							schemasName, columnNames);
					tableSchemes.setModel(model);
				}
			}
		});
		
		moduleBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			 ArrayList<String> themes=journalCtr.findAllThemes(Integer.toString( moduleBox.getSelectedIndex()+1));
			
			 
			 for(String theme: themes)
			 {
				 
				 themeBox.addItem(theme);
			 }
			 
			}
		});
		
		attachButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				String type=(String) comboBoxsSchemes.getSelectedItem();
				
				String[] row ={(String) tableSchemes.getValueAt(
						tableSchemes.getSelectedRow(), 0), type};

				

					DefaultTableModel model = (DefaultTableModel) selectedSchemes
							.getModel();
					model.addRow(row);
					
					selectedSchemes.setModel(model);
					model.fireTableDataChanged();
					

				
				
				System.out.println(row[0]);
				
				
			}
		});

		comboBoxsSchemes.setSelectedIndex(0);
		
		
		finalizeButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				String module = (moduleBox.getSelectedIndex() + 1) + "";
				String theme = (String)themeBox.getSelectedItem();
				String labScheme=null;
				String bScale=null;
				String nutRisk=null;
				String tempScheme=null;
				
				int rows=selectedSchemes.getRowCount();
				
				for(int i=0;i<rows;i++)
				{
					String type=(String) selectedSchemes.getValueAt(i, 1);
					
					if(type.equals("LabSchema"))
						labScheme=(String) selectedSchemes.getValueAt(i, 0);
					
					if(type.equals("Nutrition risk screening"))
						nutRisk=(String) selectedSchemes.getValueAt(i, 0);
					
					if(type.equals("Barden Scale"))
						bScale=(String) selectedSchemes.getValueAt(i, 0);
					
					if(type.equals("Temperature Scheme"))
						tempScheme=(String) selectedSchemes.getValueAt(i, 0);
					
				}
				
	

				try {
					journalCtr.createJournal(textField_20.getText(),
							textField_27.getText(),
							Integer.parseInt(textField_21.getText()),
							lblHospitalizationDate.getText(),
							textField_23.getText(), textField_24.getText(),
							textField_25.getText(), textField_26.getText(),
							theme, module, nutRisk, bScale,
							textField_20.getText(), labScheme,tempScheme);
				} catch (Exception ex) {
					System.out
							.println("error creating journal");
				}

			}
		});

		JPanel panel_11 = new JPanel();
		jTabbedPane1.addTab("Shemas", null, panel_11, null);
		panel_11.setLayout(new BorderLayout(0, 0));

		JPanel panel_9 = new JPanel();
		panel_11.add(panel_9, BorderLayout.NORTH);
		panel_9.setLayout(new BoxLayout(panel_9, BoxLayout.Y_AXIS));

		JPanel panel_14 = new JPanel();
		panel_9.add(panel_14);
		panel_14.setLayout(new BoxLayout(panel_14, BoxLayout.X_AXIS));

		JLabel lblNewLabel_17 = new JLabel(
				"     \r\n         \r\n         \r\n         \r\n         \r\n         \r\n         \r\n         \r\n         \r\n         \r\n         \r\n    ");
		lblNewLabel_17.setFont(new Font("Tahoma", Font.PLAIN, 78));
		panel_14.add(lblNewLabel_17);

		JPanel panel_16 = new JPanel();
		panel_9.add(panel_16);

		Box horizontalBox_2 = Box.createHorizontalBox();
		horizontalBox_2.setBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"), "Select Scheme Type",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_16.add(horizontalBox_2);

		final JComboBox comboBox_4 = new JComboBox();

		horizontalBox_2.add(comboBox_4);
		comboBox_4.setModel(new DefaultComboBoxModel(new String[] {
				"Laboratory Schemas", "Nutrition Risk Screening",
				"Braden Scale", "Tepmerature Schemas" }));

		JPanel panel_33 = new JPanel();
		panel_33.setBorder(new TitledBorder(null, "Schemas",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_11.add(panel_33, BorderLayout.CENTER);
		panel_33.setLayout(new BoxLayout(panel_33, BoxLayout.Y_AXIS));

		table_1 = new JTable();
		panel_33.add(table_1);

		JPanel panel_51 = new JPanel();
		panel_11.add(panel_51, BorderLayout.SOUTH);
		panel_51.setLayout(new BoxLayout(panel_51, BoxLayout.Y_AXIS));

		JPanel panel_15 = new JPanel();
		panel_51.add(panel_15);

		JButton createSchemeButton = new JButton("Create Scheme");

		panel_15.add(createSchemeButton);

		JButton button_1 = new JButton("Delete Scheme");
		panel_15.add(button_1);

		JButton button_2 = new JButton("Update Scheme");
		panel_15.add(button_2);

		JPanel panel_17 = new JPanel();
		panel_51.add(panel_17);
		panel_17.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		JPanel panel_31 = new JPanel();
		FlowLayout flowLayout_3 = (FlowLayout) panel_31.getLayout();
		flowLayout_3.setHgap(200);
		panel_17.add(panel_31);

		final JLabel statusLabel = new JLabel(
				"Status:                                         ");
		statusLabel.setFont(new Font("Tahoma", Font.PLAIN, 26));
		statusLabel.setForeground(new Color(0, 0, 0));
		panel_31.add(statusLabel);

		JPanel panel_32 = new JPanel();
		FlowLayout flowLayout_4 = (FlowLayout) panel_32.getLayout();
		panel_17.add(panel_32);

		JLabel lblNewLabel_18 = new JLabel(" ");
		panel_32.add(lblNewLabel_18);
		lblNewLabel_18.setFont(new Font("Tahoma", Font.PLAIN, 59));

		JPanel panel_12 = new JPanel();
		panel_11.add(panel_12, BorderLayout.WEST);
		panel_12.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		JLabel lblNewLabel_10 = new JLabel("                                ");
		panel_12.add(lblNewLabel_10);

		JPanel panel_13 = new JPanel();
		panel_11.add(panel_13, BorderLayout.EAST);

		JLabel lblNewLabel_11 = new JLabel("                                ");
		panel_13.add(lblNewLabel_11);
		getContentPane().add(jTabbedPane1, BorderLayout.CENTER);

		JScrollPane scrollPaneSchemesTable = new JScrollPane();

		table_1 = new JTable();
		table_1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		table_1.setRowSelectionAllowed(true);
		scrollPaneSchemesTable = new JScrollPane(table_1);
		panel_33.add(scrollPaneSchemesTable);

		// ------------------------------------------------------------------------------------------------------------------------

		// menu 2. Creates a menu with 38px as Item height,dark gray background
		// and white foreground, Default Aligmnet of items, two new icon for
		// Leafs.

		// ------------------------------------------------------------------------------------------------------------------------

		// menu 3. Creates a simple menu, white bacground and dark blue
		// foreground, a lightGray selection backgroun on mouseover, Right
		// Alignment for leafs
		// two icon for all Root Items, and two icon for Leaf of second menu
		// only

		// ------------------------------------------------------------------------------------------------------------------------

		comboBox_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				if (comboBox_4.getSelectedItem().equals("Braden Scale")) {

					final String[][] scalesInfo = schemeCtr
							.getAllBradenScalesInformation();

					String[] columnNames = { " Name", "Sensory Perception",
							"Moisture", "Activity", "Mobility", "Nutrition",
							"Friction and Shear" };
					DefaultTableModel model = new DefaultTableModel(scalesInfo,
							columnNames);
					table_1.setModel(model);

				}

				if (comboBox_4.getSelectedItem().equals("Laboratory Schemas")) {

					final String[][] schemasName = schemeCtr
							.getAllLabSchemeMeasurementsNames();
					String[] columnNames = { " Name" };
					DefaultTableModel model = new DefaultTableModel(
							schemasName, columnNames);
					table_1.setModel(model);
				}

				if (comboBox_4.getSelectedItem().equals(
						"Nutrition Risk Screening")) {

					String[][] schemesInfo = schemeCtr
							.getAllNutritionRiskSchemesInformation();
					String[] columnNames = { "Name",
							"Impaired Nutritional Rusk", "Severity of Disease" };

					final String[][] schemeInfoDetailed = new String[schemesInfo.length][3];

					for (int i = 0; i < schemesInfo.length; i++) {

						schemeInfoDetailed[i][0] = schemesInfo[i][0];

						switch (Integer.parseInt(schemesInfo[i][1])) {
						case 0:
							schemeInfoDetailed[i][1] = "Normal Score - 0";
							break;
						case 1:
							schemeInfoDetailed[i][1] = "Easy Score - 1";
							break;
						case 2:
							schemeInfoDetailed[i][1] = "Moderate Score - 2";
							break;
						case 3:
							schemeInfoDetailed[i][1] = "Difficult Score - 3";
							break;
						default:
							schemeInfoDetailed[i][1] = "Invalid Score";
							break;
						}

						switch (Integer.parseInt(schemesInfo[i][2])) {
						case 0:
							schemeInfoDetailed[i][2] = "Normal Score - 0";
							break;
						case 1:
							schemeInfoDetailed[i][2] = "Easy Score - 1";
							break;
						case 2:
							schemeInfoDetailed[i][2] = "Moderate Score - 2";
							break;
						case 3:
							schemeInfoDetailed[i][2] = "Difficult Score - 3";
							break;
						default:
							schemeInfoDetailed[i][2] = "Invalid Score";
							break;
						}

					}

					DefaultTableModel model = new DefaultTableModel(
							schemeInfoDetailed, columnNames);
					table_1.setModel(model);

				}

				if (comboBox_4.getSelectedItem().equals("Tepmerature Schemas")) {
					final String[][] schemasName = schemeCtr
							.getAllTemperatureMeasurementsNames();
					String[] columnNames = { " Name" };
					DefaultTableModel model = new DefaultTableModel(
							schemasName, columnNames);
					table_1.setModel(model);

				}

			}
		});

		createSchemeButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				DefaultTableModel model = (DefaultTableModel) table_1
						.getModel();

				if (comboBox_4.getSelectedItem().equals("Braden Scale")) {

					new BradenScale(statusLabel, model);

				}

				if (comboBox_4.getSelectedItem().equals("Laboratory Schemas")) {

					new LabScheme(statusLabel, model);
				}

				if (comboBox_4.getSelectedItem().equals(
						"Nutrition Risk Screening")) {

					new GUINutritionRisk(statusLabel, model);
				}

				if (comboBox_4.getSelectedItem().equals("Tepmerature Schemas")) {

					new Temperature(statusLabel, model);

				}

			}

		});

		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				if (comboBox_4.getSelectedIndex() == 2) {
					schemeCtr.deleteBradenScale((String) table_1.getValueAt(
							table_1.getSelectedRow(), 0));
				}

				if (comboBox_4.getSelectedIndex() == 0) {
					schemeCtr.deleteLabScheme(((String) table_1.getValueAt(
							table_1.getSelectedRow(), 0)));
				}

				if (comboBox_4.getSelectedIndex() == 1) {
					schemeCtr.deleteNutritionRiskScheme(((String) table_1
							.getValueAt(table_1.getSelectedRow(), 0)));
				}

				((DefaultTableModel) table_1.getModel()).removeRow(table_1
						.getSelectedRow());

				statusLabel.setForeground(new Color(0, 128, 0));
				statusLabel.setText("Status: Scheme Succesfully Deleted!");

			}
		});

		setButtons();
	}

	/**
	 * Simple bind of an action to a single Menu Leaf Item. This is the most
	 * important aspect of menu.
	 */
	public void setButtons() {

		for (AccordionLeafItem leaf : menu1.getAllLeafs()) {

			String module = leaf.getName();
			Pattern intsOnly = Pattern.compile("\\d+");
			Matcher makeMatch = intsOnly.matcher(module);
			makeMatch.find();
			String inputInt = makeMatch.group();
			System.out.println(inputInt);
			String theme = leaf.getText();
			final String[][] journalInfo = journalCtr.getAllJournals(theme, ""
					+ inputInt);

			MouseAdapter adapter = new MouseAdapter() {

				@Override
				public void mousePressed(MouseEvent e) {

					String[] columnNames = { " Journal Name", "Contact Causes" };
					DefaultTableModel model = new DefaultTableModel(
							journalInfo, columnNames);
					table.setModel(model);
					table.setVisible(true);

				}
			};
			leaf.addMouseListener(adapter);
		}
	}

	/**
	 * <code>First method to create an AccordionMenu: create a description string of menu tree.</code>
	 * It creates a Standard Description String to create an AccordionMenu. This
	 * is the full structure of a correct description string.
	 * 
	 * @return description String.
	 */
	public String getSampleMenuDescriptor() {
		String menuDescriptor = "" + "Module 1,menu1:" + "Theme 1,submenu1.1;"
				+ "Theme 2,submenu1.2;" + "Theme 3,exit;"
				+ "Theme 4, submenu1.4" + "!" + "Module 2,menu2:"
				+ "Sub Menu 1,submenu2.1;" + "Sub Menu 2,submenu2.2;"
				+ "Sub Menu 3,submenu2.3;" + "!" + "Module 3,menu3:"
				+ "Sub Menu 1,submenu3.1;" + "Sub Menu 2,submenu3.2;"
				+ "Sub Menu 3,submenu3.3;" + "!" + "Module 4,menu4:"
				+ "Sub Menu 1,submenu4.1;" + "Sub Menu 2,submenu4.2;"
				+ "Sub Menu 3,submenu4.3;";
		return menuDescriptor;
	}

	public String getMenuDescriptor() {
		String menuDescriptor = "";
		for (int i = 1; i <= 12; i++) {
			JournalCtr controller = new JournalCtr();
			menuDescriptor += "Module " + i + ",menu" + i + ":";
			try {
				if (controller.findAllThemes("" + i).size() != 0) {
					int j = 1;

					for (String s : controller.findAllThemes("" + i)) {
						menuDescriptor += s + ",submenu" + i + "." + j + ";";
						j++;
					}
				} else {
					menuDescriptor += "No theme in this module,submenu" + i
							+ ".1;";
				}

			}

			catch (Exception e) {

			}
			if (i != 12) {
				menuDescriptor += "!";
			}
		}
		menuDescriptor += ";";

		return menuDescriptor;
	}

	/**
	 * <code>Second method to create an AccordionMenu: add manually each menu with its leafs to AccordionMenu.</code>
	 * It creates manually a structure like one created before with a
	 * description String. First method is better when menu structure is static.
	 * Use this method instead if you want to create structure dinamically.
	 * 
	 * @param target
	 *            Target AccordionMenu to modify.
	 */
	public void createSampleMenuStructure(AccordionMenu target) {
		target.addNewMenu("menu1", "Menu One");
		target.addNewLeafTo("menu1", "submenu1.1", "Sub Menu 1");
		target.addNewLeafTo("menu1", "submenu1.2", "Sub Menu 2");
		target.addNewLeafTo("menu1", "submenu1.3", "Sub Menu 3");

		target.addNewMenu("menu2", "Menu Two");
		target.addNewLeafTo("menu2", "submenu2.1", "Sub Menu 1");
		target.addNewLeafTo("menu2", "submenu2.2", "Sub Menu 2");
		target.addNewLeafTo("menu2", "submenu2.3", "Sub Menu 3");

		target.addNewMenu("menu3", "Menu Three");
		target.addNewLeafTo("menu3", "submenu3.1", "Sub Menu 1");
		target.addNewLeafTo("menu3", "submenu3.2", "Sub Menu 2");
		target.addNewLeafTo("menu3", "submenu3.3", "Sub Menu 3");

		target.addNewMenu("menu4", "Menu Four");
		target.addNewLeafTo("menu4", "submenu4.1", "Sub Menu 1");
		target.addNewLeafTo("menu4", "submenu4.2", "Sub Menu 2");
		target.addNewLeafTo("menu4", "submenu4.3", "Sub Menu 3");
		target.calculateAvaiableSpace();
	}

	/**
	 * Simple example to browse all Leaf of menu. In this case for each leaf it
	 * adds a new Mouse Adapter.
	 * 
	 * @param menu
	 *            Target Menu to modify.
	 */
	public void setMouseAdapter(AccordionMenu menu) {
		for (AccordionLeafItem leaf : menu.getAllLeafs()) {
			leaf.addMouseListener(getSimpleMouseAdapter());
		}
	}

	/**
	 * Creates a simple MouseAdapter binded to an AccordionItem. On mouse
	 * Pressed it writes on a textBox the source of event.
	 * 
	 * @return {@link MouseAdapter} object.
	 */
	public MouseAdapter getSimpleMouseAdapter() {
		return new MouseAdapter() {

			@Override
			public void mousePressed(MouseEvent e) {
				AccordionItem item = (AccordionItem) e.getSource();

			}
		};
	}

	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jTabbedPane1 = new javax.swing.JTabbedPane();
		jPanel3 = new javax.swing.JPanel();
		jPanel1 = new javax.swing.JPanel();
		cont1 = new javax.swing.JPanel();
		jPanel5 = new javax.swing.JPanel();
		jPanel6 = new javax.swing.JPanel();
		jPanel7 = new javax.swing.JPanel();
		jPanel7.setBorder(new TitledBorder(null, "", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		jPanel4 = new javax.swing.JPanel();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setBackground(new java.awt.Color(255, 204, 204));

		jPanel1.setOpaque(false);

		cont1.setBackground(new java.awt.Color(204, 204, 204));
		cont1.setBorder(javax.swing.BorderFactory
				.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
		cont1.setLayout(new javax.swing.BoxLayout(cont1,
				javax.swing.BoxLayout.LINE_AXIS));

		jPanel5.setLayout(new javax.swing.BoxLayout(jPanel5,
				javax.swing.BoxLayout.Y_AXIS));

		jPanel5.add(jPanel6);
		jPanel6.setLayout(new BorderLayout(0, 0));

		panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		jPanel6.add(panel, BorderLayout.CENTER);
		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

		horizontalBox = new JPanel();
		horizontalBox.setBorder(new TitledBorder(null, "Journal List",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.add(horizontalBox);
		horizontalBox.setLayout(new BoxLayout(horizontalBox, BoxLayout.X_AXIS));

		JScrollPane scrollPane = new JScrollPane();
		horizontalBox.add(scrollPane);

		table = new JTable();
		scrollPane.setViewportView(table);
		table.setModel(new DefaultTableModel(new Object[][] {}, new String[] {}));

		panel_2 = new JPanel();
		panel_2.setAlignmentX(Component.LEFT_ALIGNMENT);
		panel.add(panel_2);
		panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.Y_AXIS));

		panel_4 = new JPanel();
		panel_2.add(panel_4);

		panel_3 = new JPanel();
		panel_2.add(panel_3);
		panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.Y_AXIS));

		panel_7 = new JPanel();
		panel_3.add(panel_7);

		panel_6 = new JPanel();
		panel_3.add(panel_6);
		panel_6.setLayout(new BoxLayout(panel_6, BoxLayout.X_AXIS));

		JPanel panel_53 = new JPanel();
		FlowLayout fl_panel_53 = (FlowLayout) panel_53.getLayout();
		fl_panel_53.setAlignment(FlowLayout.RIGHT);
		panel_6.add(panel_53);

		JPanel panel_54 = new JPanel();
		panel_6.add(panel_54);
		panel_54.setLayout(new BoxLayout(panel_54, BoxLayout.X_AXIS));

		JPanel panel_55 = new JPanel();
		panel_54.add(panel_55);

		JPanel panel_56 = new JPanel();
		panel_54.add(panel_56);
		panel_56.setLayout(new BoxLayout(panel_56, BoxLayout.X_AXIS));

		JPanel panel_33 = new JPanel();
		panel_33.setBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"), "", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		panel_56.add(panel_33);
		panel_33.setLayout(new BoxLayout(panel_33, BoxLayout.X_AXIS));

		JPanel panel_13 = new JPanel();
		panel_33.add(panel_13);
		panel_13.setLayout(new BoxLayout(panel_13, BoxLayout.Y_AXIS));

		JPanel panel_27 = new JPanel();
		panel_13.add(panel_27);

		JPanel panel_28 = new JPanel();
		panel_28.setBorder(new TitledBorder(null, "Bed Selection",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_13.add(panel_28);
		panel_28.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		comboBox99 = new JComboBox();
		panel_28.add(comboBox99);

		JPanel panel_29 = new JPanel();
		panel_13.add(panel_29);

		JPanel panel_10 = new JPanel();
		panel_33.add(panel_10);
		panel_10.setLayout(new BoxLayout(panel_10, BoxLayout.Y_AXIS));

		JPanel panel_30 = new JPanel();
		panel_10.add(panel_30);

		panel_31 = new JPanel();
		panel_31.setBorder(new TitledBorder(null, "Confirm",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_10.add(panel_31);
		
		final JButton btnCreateSession = new JButton("Create Session");
		btnCreateSession.setEnabled(false);

		JButton btnSelect = new JButton("Select");
		btnSelect.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnSelect.addMouseListener(new MouseAdapter() {
			@Override
			
			
			public void mouseClicked(MouseEvent arg0) {
				
				btnCreateSession.setEnabled(true);
				String bedNo = "";
				try {
					String bed = comboBox99.getSelectedItem().toString();
					bedNo = getNumberFromText(bed) + "";
				} catch (Exception ex) {

				}
				String[] row = { bedNo,
						table.getValueAt(table.getSelectedRow(), 0).toString(),
						table.getValueAt(table.getSelectedRow(), 1).toString() };

				if (table_2.getRowCount() < sessionCtr.getNrOfBeds(roomNo)) {

					DefaultTableModel model = (DefaultTableModel) table_2
							.getModel();
					model.addRow(row);
					table_2.setModel(model);
				}

				comboBox99.removeAllItems();
				if (getUnoccupiedBeds().size() != 0) {
					for (int j : getUnoccupiedBeds()) {
						String s = "Bed " + j;
						comboBox99.addItem(s);
					}
				}

			}
		});
		panel_31.add(btnSelect);

		JPanel panel_32 = new JPanel();
		panel_10.add(panel_32);

		JPanel panel_12 = new JPanel();
		panel_56.add(panel_12);
		panel_12.setLayout(new BoxLayout(panel_12, BoxLayout.X_AXIS));

		JPanel panel_15 = new JPanel();
		panel_12.add(panel_15);

		JPanel panel_14 = new JPanel();
		panel_12.add(panel_14);

		JPanel panel_16 = new JPanel();
		panel_12.add(panel_16);
		panel_16.setLayout(new BoxLayout(panel_16, BoxLayout.Y_AXIS));

		panel_8 = new JPanel();
		panel_3.add(panel_8);

		panel_5 = new JPanel();
		panel_2.add(panel_5);

		panel_9 = new JPanel();
		panel.add(panel_9);
		panel_9.setLayout(new BoxLayout(panel_9, BoxLayout.X_AXIS));

		jPanel5.add(jPanel7);
		jPanel7.setLayout(new BorderLayout(0, 0));

		panel_1 = new JPanel();
		jPanel7.add(panel_1, BorderLayout.CENTER);
		panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));

		JPanel horizontalBox_1 = new JPanel();
		horizontalBox_1.setBorder(new TitledBorder(null, "Journals Selected",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_1.add(horizontalBox_1);
		horizontalBox_1.setLayout(new BoxLayout(horizontalBox_1,
				BoxLayout.Y_AXIS));

		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1
				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scrollPane_1
				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

		horizontalBox_1.add(scrollPane_1);

		table_2 = new JTable();
		scrollPane_1.setViewportView(table_2);
		table_2.setModel(new DefaultTableModel(new Object[][] {

		}, new String[] { "Room No", "Journal Name", "Contact Causes" }));

		JButton btnDelete = new JButton("Delete selected journal");
		btnDelete.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				DefaultTableModel model = (DefaultTableModel) table_2
						.getModel();

				model.removeRow(table_2.getSelectedRow());

				table_2.setModel(model);
				comboBox99.removeAllItems();
				if (getUnoccupiedBeds().size() != 0) {
					for (int j : getUnoccupiedBeds()) {
						String s = "Bed " + j;
						comboBox99.addItem(s);
					}
				}
			}
		});
		horizontalBox_1.add(btnDelete);

		JPanel panel_11 = new JPanel();
		panel_1.add(panel_11);
		panel_11.setLayout(new BoxLayout(panel_11, BoxLayout.Y_AXIS));

		JPanel panel_20 = new JPanel();
		panel_11.add(panel_20);
		panel_20.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		JPanel panel_17 = new JPanel();
		panel_11.add(panel_17);

		JPanel panel_18 = new JPanel();
		panel_11.add(panel_18);
		panel_18.setLayout(new BoxLayout(panel_18, BoxLayout.X_AXIS));

		JPanel panel_22 = new JPanel();
		panel_18.add(panel_22);

		JPanel panel_23 = new JPanel();
		panel_18.add(panel_23);

		JPanel panel_24 = new JPanel();
		panel_18.add(panel_24);
		panel_24.setLayout(new BoxLayout(panel_24, BoxLayout.Y_AXIS));

		JPanel panel_35 = new JPanel();
		panel_24.add(panel_35);

		JPanel panel_36 = new JPanel();
		panel_24.add(panel_36);

		JPanel panel_37 = new JPanel();
		panel_24.add(panel_37);

		JPanel panel_25 = new JPanel();
		panel_25.setBorder(new TitledBorder(null, "", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		panel_18.add(panel_25);
		panel_25.setLayout(new BoxLayout(panel_25, BoxLayout.Y_AXIS));

		JPanel panel_38 = new JPanel();
		panel_25.add(panel_38);

		JPanel panel_39 = new JPanel();
		panel_25.add(panel_39);


		
		btnCreateSession.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {

				lst = new ArrayList<String>();
				for (int i = 0; i < table_2.getRowCount(); i++) {
					lst.add(table_2.getValueAt(i, 0).toString() + "."
							+ table_2.getValueAt(i, 1).toString() + ":"
							+ table_2.getValueAt(i, 2).toString());
				}
				try {
					sessionCtr.finalizeSession(textFieldLabel.getText(),
							roomNo, textFieldTeacher.getText(), lst);
					lblStatus.setText("Status: Session created succesfuly");
				} catch (Exception ex) {
					lblStatus.setText("Status: Error in creation of session");
				}

				// Get all item objects

			}
		});
		panel_39.add(btnCreateSession);

		JPanel panel_40 = new JPanel();
		panel_25.add(panel_40);

		lblStatus = new JLabel("Status: ");
		lblStatus.setFont(new Font("Tahoma", Font.PLAIN, 24));
		panel_40.add(lblStatus);

		JPanel panel_26 = new JPanel();
		panel_18.add(panel_26);

		JPanel panel_34 = new JPanel();
		panel_18.add(panel_34);

		JPanel panel_19 = new JPanel();
		panel_11.add(panel_19);

		JPanel panel_21 = new JPanel();
		panel_11.add(panel_21);

		javax.swing.GroupLayout gl_jPanel1 = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(gl_jPanel1);
		gl_jPanel1
				.setHorizontalGroup(gl_jPanel1
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								gl_jPanel1
										.createSequentialGroup()
										.addGap(0, 0, 0)
										.addComponent(
												cont1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												208,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(470, Short.MAX_VALUE))
						.addGroup(
								gl_jPanel1
										.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
										.addGroup(
												javax.swing.GroupLayout.Alignment.TRAILING,
												gl_jPanel1
														.createSequentialGroup()
														.addGap(210, 210, 210)
														.addComponent(
																jPanel5,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.addContainerGap())));
		gl_jPanel1.setVerticalGroup(gl_jPanel1
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(cont1, javax.swing.GroupLayout.DEFAULT_SIZE, 329,
						Short.MAX_VALUE)
				.addGroup(
						gl_jPanel1.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
								.addComponent(jPanel5,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));

		javax.swing.GroupLayout gl_jPanel3 = new javax.swing.GroupLayout(
				jPanel3);
		jPanel3.setLayout(gl_jPanel3);
		gl_jPanel3
				.setHorizontalGroup(gl_jPanel3
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								gl_jPanel3
										.createSequentialGroup()
										.addGroup(
												gl_jPanel3
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addGroup(
																gl_jPanel3
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				jPanel1,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE))
														.addGroup(
																gl_jPanel3
																		.createSequentialGroup()
																		.addGap(23,
																				23,
																				23)
																		.addComponent(
																				jPanel4,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)))
										.addContainerGap()));
		gl_jPanel3.setVerticalGroup(gl_jPanel3.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				gl_jPanel3
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(jPanel4,
								javax.swing.GroupLayout.PREFERRED_SIZE, 37,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(18, 18, 18)
						.addComponent(jPanel1,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE).addContainerGap()));

		JButton btnSelectDate = new JButton("Calendar");
		btnSelectDate.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				new Calendar(textFieldLabel);

			}
		});

		textFieldLabel = new JTextField();
		textFieldLabel.setEditable(false);
		textFieldLabel.setOpaque(true);
		textFieldLabel.setBorder(null);

		textFieldLabel.getDocument().addDocumentListener(
				new DocumentListener() {

					public void removeUpdate(DocumentEvent e) {
						roomComboBox.removeAllItems();
						for (int k : sessionCtr
								.getUnoccupiedRooms(textFieldLabel.getText())) {
							roomComboBox.addItem("Room  " + k);
						}
					}

					public void insertUpdate(DocumentEvent e) {
						roomComboBox.removeAllItems();
						for (int k : sessionCtr
								.getUnoccupiedRooms(textFieldLabel.getText())) {
							roomComboBox.addItem("Room  " + k);
						}

					}

					public void changedUpdate(DocumentEvent e) {
						roomComboBox.removeAllItems();
						for (int k : sessionCtr
								.getUnoccupiedRooms(textFieldLabel.getText())) {
							roomComboBox.addItem("Room  " + k);
						}
					}
				});
		jPanel4.add(textFieldLabel);
		textFieldLabel.setColumns(10);
		jPanel4.add(btnSelectDate);

		roomComboBox = new JComboBox();
		if (roomComboBox.getItemCount() == 0) {
			for (int k : sessionCtr
					.getUnoccupiedRooms(textFieldLabel.getText())) {
				roomComboBox.addItem("Room  " + k);
			}
		}
		jPanel4.add(roomComboBox);

		JLabel lblTeacher = new JLabel("Teacher:");
		jPanel4.add(lblTeacher);

		textFieldTeacher = new JTextField();
		jPanel4.add(textFieldTeacher);
		textFieldTeacher.setColumns(10);
		if (roomComboBox.getItemCount() == 0) {
			for (int k : sessionCtr
					.getUnoccupiedRooms(textFieldLabel.getText())) {
				roomComboBox.addItem("Room  " + k);
			}
		}

		roomComboBox.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				try {
					String comboBoxSelected = roomComboBox.getSelectedItem()
							.toString();
					int room_No = getNumberFromText(comboBoxSelected);
					roomNo = room_No;

					comboBox99.removeAllItems();
					for (int i : getUnoccupiedBeds()) {

						comboBox99.addItem("Bed " + i);
					}

					System.out.println(roomNo);
				}

				catch (Exception ex) {

				}

			}

		});

		jTabbedPane1.addTab("Create Session", jPanel3);

		pack();

	}// </editor-fold>

	public ArrayList<Integer> getUnoccupiedBeds() {
		ArrayList<Integer> listOc = new ArrayList<Integer>();
		ArrayList<Integer> listUnoc = new ArrayList<Integer>();
		if (table_2.getModel().getRowCount() != 0) {

			for (int i = 0; i < table_2.getModel().getRowCount(); i++) {
				String s = table_2.getValueAt(i, 0).toString();

				listOc.add(getNumberFromText(s));

			}
		}

		for (int i = 1; i <= sessionCtr.getNrOfBeds(roomNo); i++) {
			if (!listOc.contains(i)) {

				listUnoc.add(i);
			}
		}
		
		return listUnoc;
	}

	public int getNumberFromText(String text) {
		Pattern intsOnly = Pattern.compile("\\d+");
		Matcher makeMatch = intsOnly.matcher(text);
		makeMatch.find();
		String inputInt = makeMatch.group();
		int nr = Integer.parseInt(inputInt);
		return nr;

	}

	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				NewJFrame frame = new NewJFrame();
				frame.pack();
				frame.setVisible(true);

			}
		});
	}

	// Variables declaration - do not modify
	private javax.swing.JPanel cont1;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel3;
	private javax.swing.JPanel jPanel4;
	private javax.swing.JPanel jPanel5;
	private javax.swing.JPanel jPanel6;
	private javax.swing.JPanel jPanel7;
	private javax.swing.JTabbedPane jTabbedPane1;
	private JPanel panel;
	private JPanel panel_1;
	private JPanel horizontalBox;
	private JPanel panel_2;
	private JPanel panel_3;
	private JPanel panel_4;
	private JPanel panel_5;
	private JPanel panel_6;
	private JPanel panel_7;
	private JPanel panel_8;
	private JPanel panel_9;
	private ArrayList<String> lst;
	private JTextField textField_27;
	private JTable table_1;
	private JTable table;
	private JTable table_2;
	private JTextField textFieldLabel;
	private String[][] list_1;

	private JTextField textFieldTeacher;
	private JLabel lblStatus;
	private JComboBox roomComboBox;
	private JComboBox comboBox99;
	public int roomNo;
	private JTable table_3;
	private JTable tableSchemes;
	private JTable selectedSchemes;

}
